package easybooking;

import easybooking.data.Airline;
import easybooking.data.AirlineImpl;
import easybooking.data.Airport;
import easybooking.data.AirportImpl;
import easybooking.data.Booking;
import easybooking.data.BookingImpl;
import easybooking.data.Customer;
import easybooking.data.CustomerImpl;
import easybooking.data.Flight;
import easybooking.data.FlightImpl;
import easybooking.data.Plane;
import easybooking.data.PlaneImpl;
import easybooking.data.Seat;
import easybooking.data.SeatImpl;
import easybooking.data.Type;
import easybooking.data.TypeImpl;
import easybooking.db.AirlineMapper;
import easybooking.db.CustomerMapper;
import easybooking.db.AirportMapper;
import easybooking.db.BookingMapper;
import easybooking.db.FlightMapper;
import easybooking.db.PlaneMapper;
import easybooking.db.SeatMapper;
import easybooking.db.TypeMapper;
import easybooking.report.ReportGenerator;
import easybooking.report.ReportGeneratorImpl;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.*;

// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
// #[regen=yes,id=DCE.12190274-1D35-DE7C-6CB7-1E0F893144E7]
// </editor-fold>
/**
 * Implementation of the Interface <code>FlightManagement</code>.
 * @see FlightManagement
 * @author Hakan Keles
 */
public class FlightManagementImpl extends UnicastRemoteObject implements FlightManagement {

    private BookingMapper bMapper = null;
    private FlightMapper fMapper = null;
    private CustomerMapper cMapper = null;
    private AirportMapper airpMapper = null;
    private PlaneMapper pMapper = null;
    private AirlineMapper airlMapper = null;
    private TypeMapper tMapper = null;
    private SeatMapper sMapper = null;
    private ReportGenerator reportGenerator = null;

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.CC2AD015-38E4-C068-AA06-C134FDA61EDC]
    // </editor-fold>
    /**
     *
     * @param b Booking Mapper Object
     * @param f Flight Mapper Object
     * @param c Customer Mapper Object
     * @param airp Airport Mapper Object
     * @param p Plane Mapper Object
     * @param airl Airline Mapper Object
     * @param t Type Mapper Object
     * @param s Seat Mapper Object
     * @throws RemoteException
     */
    public FlightManagementImpl(BookingMapper b, FlightMapper f, CustomerMapper c, AirportMapper airp, PlaneMapper p, AirlineMapper airl, TypeMapper t, SeatMapper s) throws RemoteException {
        this.bMapper = b;
        this.fMapper = f;
        this.cMapper = c;
        this.airpMapper = airp;
        this.pMapper = p;
        this.airlMapper = airl;
        this.tMapper = t;
        this.sMapper = s;
    }

    /**
     * Creates a new customer object
     * @param firstname The firstname of the created customer
     * @param lastname The lastname of the created customer
     * @param street The street of the created customer
     * @param zip The zip of the created customer
     * @param city The city of the created customer
     * @return the created customer object
     */
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.BF9DB95E-628D-86DE-3903-1A40E290ABD9]
    // </editor-fold>
    public Customer createCustomer(String firstname, String lastname, String street, int zip, String city) throws RemoteException {
        Customer c = new CustomerImpl();
        c.setFirstname(firstname);
        c.setLastname(lastname);
        c.setStreet(street);
        c.setCity(city);
        c.setZip(zip);
        c.setIsActive(true);
        return this.cMapper.insert(c);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.1ED5724F-906E-AD32-CD16-0A7E50049A59]
    // </editor-fold>
    /**
     * deactivates a customer object and all booking objects which are associated to them
     * @param c is the customer object which should be deactivated
     */
    public void deactivate(Customer c) throws RemoteException {
        Vector bv = bMapper.findByCustomer(c);
        Iterator bi = bv.iterator();
        while (bi.hasNext()) {
            Booking b = (Booking) bi.next();
            deactivate(b);
        }
        c.setIsActive(false);
        cMapper.update(c);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.95652CC8-A77E-1A57-9AA6-EB19458FD828]
    // </editor-fold>
    /**
     * inserts a changed customer object back into the DB
     * @param c is the customer object which has been changed
     */
    public void save(Customer c) throws RemoteException {
        this.cMapper.update(c);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.9E6AEEEC-BBF3-A75F-EFC8-04AC68AD179C]
    // </editor-fold>
    /**
     * inserts a changed airl object back into the DB
     * @param airl is the airline object which has been changed
     */
    public void save(Airline airl) throws RemoteException {
        this.airlMapper.update(airl);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.337FE309-F794-4F5E-4712-80626FA38FC0]
    // </editor-fold>
    /**
     * inserts a changed airport object back into the DB
     * @param airp is the airport object which has been changed
     */
    public void save(Airport airp) throws RemoteException {
        this.airpMapper.update(airp);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.D21B8896-C48A-19B3-A240-F13207C351AB]
    // </editor-fold>
    /**
     * inserts a changed booking object back into the DB
     * @param b is the booking object which has been changed
     */
    public void save(Booking b) throws RemoteException {
        this.bMapper.update(b);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.00D11F42-F50E-19CB-6CCD-7D21B305AA48]
    // </editor-fold>
    /**
     * inserts a changed flight object back into the DB
     * @param f is the flight object which has been changed
     */
    public void save(Flight f) throws RemoteException {
        this.fMapper.update(f);

    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.4E5085FC-4AC5-9F7F-3D6E-43B58F7A5495]
    // </editor-fold>
    /**
     * inserts a changed plane object back into the DB
     * @param p is the plane object which has been changed
     */
    public void save(Plane p) throws RemoteException {

        Plane oldPlane = pMapper.findByKey(p.getPlaneId());

        if (p.getTypeId() != oldPlane.getTypeId()) {
            Vector sv = sMapper.findByPlane(p);
            Iterator si = sv.iterator();
            while (si.hasNext()) {
                Seat s = (Seat) si.next();
                deactivate(s);
            }
            Type t = new TypeImpl();
            t = findTypeByKey(p.getTypeId());
            for (int i = 1; i <= t.getRows(); i++) {
                for (int j = 1; j <= t.getColumns(); j++) {
                    // create seats for plane
                    Seat s = new SeatImpl();
                    char seat = (char) ('A' + j - 1);
                    createSeat(i, seat, p.getPlaneId());
                }
            }




        }

        this.pMapper.update(p);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.CAB2954C-BA5E-A340-470A-9D424B785503]
    // </editor-fold>
    /**
     * inserts a changed seat object back into the DB
     * @param s is the seat object which has been changed
     */
    public void save(Seat s) throws RemoteException {
        this.sMapper.update(s);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.59716D92-D618-AC19-A0CD-FA25DBAB055A]
    // </editor-fold>
    /**
     * inserts a changed type object back into the DB
     * @param t is the type object which has been changed
     */
    public void save(Type t) throws RemoteException {
        this.tMapper.update(t);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.4B4358D2-590E-3226-855A-873226649308]
    // </editor-fold>
    /**
     *returns all customer objects from the DB
     *@return a customer Vector with all customers
     */
    public Vector<Customer> getAllCustomers() throws RemoteException {
        return this.cMapper.findAll();
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.9A50FC71-5216-16C7-EFD9-DF7AE9CF3473]
    // </editor-fold>
    /**
     * @return all airline objects from the DB
     */
    public Vector<Airline> getAllAirlines() throws RemoteException {
        return this.airlMapper.findAll();
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.3ED149D6-B862-C5EE-69EE-9B63AA1AC2DD]
    // </editor-fold>
    /**
     * @return all airport objects from the DB
     */
    public Vector<Airport> getAllAirports() throws RemoteException {
        // Testing
        return this.airpMapper.findAll();
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.32BD3E07-81A1-FB89-008E-5870BC2803AE]
    // </editor-fold>
    /**
     * @return all booking objects from the DB
     */
    public Vector<Booking> getAllBookings() throws RemoteException {
        return this.bMapper.findAll();
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.FC18D264-51C9-F73E-4BFF-6C1500F0A06E]
    // </editor-fold>
    /**
     * @return all flight objects from the DB
     */
    public Vector<Flight> getAllFlights() throws RemoteException {
        return this.fMapper.findAll();
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.F4407255-8DD6-B3DA-B6D0-82FDF15E6C8B]
    // </editor-fold>
    /**
     * @return all plane objects from the DB
     */
    public Vector<Plane> getAllPlanes() throws RemoteException {
        return this.pMapper.findAll();
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.BFA876C4-9465-A4A3-8C51-44B79E10EA17]
    // </editor-fold>
    /**
     * @return all seat objects from the DB
     */
    public Vector<Seat> getAllSeats() throws RemoteException {
        return this.sMapper.findAll();
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.7882D536-A7DF-C811-4441-69778277A4F0]
    // </editor-fold>
    /**
     * @return all type objects from the DB
     */
    public Vector<Type> getAllTypes() throws RemoteException {
        return this.tMapper.findAll();
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.20447DC0-D19D-2BB6-AE58-D3F2E2BFBD24]
    // </editor-fold>
    /**
     * Creates a new airline object
     * @param name The name of the airline
     * @param initials The initials of the created airline
     * @return the created airline object
     */
    public Airline createAirline(String name, String initials) throws RemoteException {
        Airline airl = new AirlineImpl();
        airl.setName(name);
        airl.setInitials(initials);
        airl.setIsActive(true);
        // save Objekt in the DB
        return this.airlMapper.insert(airl);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.0E372EAB-FC57-F384-D2DE-CFE47E244A20]
    // </editor-fold>
    /**
     * Creates a new airport object
     * @param name The name of the created airport
     * @param initials The initials of the created airport
     * @param city The city of the created airport
     * @return the created airport object
     */
    public Airport createAirport(String name, String initials, String city) throws RemoteException {

        Airport airp = new AirportImpl();
        airp.setName(name);
        airp.setInitials(initials);
        airp.setCity(city);
        airp.setIsActive(true);
        // save Objekt in the DB
        return this.airpMapper.insert(airp);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.89271713-B221-84BE-8B48-A6EBE806A3C5]
    // </editor-fold>
    /**
     * Creates a new booking object
     * @param dateTime The Date and the Time of the created booking
     * @param customerId Association to the customer of the created booking
     * @param flightId Association to the flight of the created booking
     * @param seatId Association to the seat of the created booking
     * @return the created booking object
     */
    public Booking createBooking(Date dateTime, int customerId, int flightId, int seatId) throws RemoteException {
        Booking b = new BookingImpl();
        b.setDateTime(dateTime);
        b.setCustomerId(customerId);
        b.setFlightId(flightId);
        b.setSeatId(seatId);
        b.setIsCheckedIn(false);
        b.setCheckedInDateTime(new Date(0));


        b.setIsActive(true);
        // save Objekt in the DB
        return this.bMapper.insert(b);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.D47D8856-5304-43A7-7206-9B1F2E5FC5EF]
    // </editor-fold>
    /**
     * Creates a new flight object
     * @param dateTime The Date and the time of the created flight
     * @param planeId Association to the plane of the created flight
     * @param startAirportId Association to the startAirport of the created flight
     * @param stopAirportId Association to the stopAirportId of the created flight
     * @return the created flight object
     */
    public Flight createFlight(Date dateTime, int planeId, int startAirportId, int stopAirportId) throws RemoteException {
        Flight f = new FlightImpl();
        f.setDateTime(dateTime);
        f.setPlaneId(planeId);
        f.setStartAirportId(startAirportId);
        f.setDestAirportId(stopAirportId);
        f.setIsActive(true);

        // save Objekt in the DB
        return this.fMapper.insert(f);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.6A4B073E-2200-2AF0-2DD4-696AA9675F06]
    // </editor-fold>
    /**
     * Creates a new plane object
     * @param typeId Association to the type of the created plane
     * @param airlineId Association to the airline of the created plane
     * @param name The name of the created plane
     * @return the created plane object
     */
    public Plane createPlane(int typeId, int airlineId, String name) throws RemoteException {
        Plane p = new PlaneImpl();
        p.setName(name);
        p.setTypeId(typeId);
        p.setAirlineId(airlineId);
        p.setIsActive(true);

        // save Objekt in the DB
        p = this.pMapper.insert(p);

        // get type of plane
        Type t = new TypeImpl();
        t = findTypeByKey(p.getTypeId());
        for (int i = 1; i <= t.getRows(); i++) {
            for (int j = 1; j <= t.getColumns(); j++) {
                // create seats for plane
                Seat s = new SeatImpl();
                char seat = (char) ('A' + j - 1);
                createSeat(i, seat, p.getPlaneId());
            }
        }
        return p;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.E82252A7-CDDD-DFB8-63BB-4E60D30D0543]
    // </editor-fold>
    /**
     * Creates a new seat object
     * @param row The row of the created seat
     * @param seat The seat of the created seat
     * @param planeId Association to the plane of the created seat
     * @return the created seat object
     */
    public Seat createSeat(int row, char seat, int planeId) throws RemoteException {
        Seat s = new SeatImpl();
        s.setRow(row);
        s.setSeat(seat);
        s.setPlaneId(planeId);
        s.setIsActive(true);
        // save Objekt in the DB
        return this.sMapper.insert(s);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.358E5773-3AEF-1800-9C00-3AF4E74B3735]
    // </editor-fold>
    /**
     * Creates a new type object
     * @param name The name of the created type
     * @param rows The rows of the created type
     * @param columns The columns of the created type
     * @return the created type object
     */
    public Type createType(String name, int rows, int columns) throws RemoteException {
        Type t = new TypeImpl();
        t.setName(name);
        t.setRows(rows);
        t.setColumns(columns);
        t.setIsActive(true);
        // save Objekt in the DB
        return this.tMapper.insert(t);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.EE8841F7-291D-3CD0-AAC5-11D7A371A455]
    // </editor-fold>
    /**
     * deactivates an airline object and all plane objects which are associated to them
     * @param airl is the airline object which should be deactivated
     */
    public void deactivate(Airline airl) throws RemoteException {
        Vector pv = pMapper.findByAirline(airl);
        Iterator pi = pv.iterator();
        while (pi.hasNext()) {
            Plane p = (Plane) pi.next();
            deactivate(p);
        }
        airl.setIsActive(false);
        airlMapper.update(airl);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker ">
    // #[regen=yes,id=DCE.E6E2E145-7FB2-F3B6-EF49-E59C16DEAAD6]
    // </editor-fold>
    /**
     * deactivates an airport object and all flight objects which are associated to them
     * @param airp is the airport object which should be deactivated
     */
    public void deactivate(Airport airp) throws RemoteException {
        Vector fv = fMapper.findByStartAirport(airp);
        fv.addAll(fMapper.findByDestAirport(airp));
        Iterator fi = fv.iterator();
        while (fi.hasNext()) {
            Flight f = (Flight) fi.next();
            deactivate(f);
        }
        airp.setIsActive(false);
        airpMapper.update(airp);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker ">
    // #[regen=yes,id=DCE.44EA0B74-186B-0CF1-1DF7-0BC5B4A410A1]
    // </editor-fold>
    /**
     * deactivates a booking object
     * @param b is the booking object which should be deactivated
     */
    public void deactivate(Booking b) throws RemoteException {
        if (findFlightByKey(b.getFlightId()).getDateTime().after(new Date())) {
            b.setIsActive(false);
            bMapper.update(b);
        }
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.1ED8598A-3580-611B-B7E3-BCCE0AA6DA3B]
    // </editor-fold>
    /**
     * deactivates a flight object and all booking objects which are associated to them
     * @param f is the flight object which should be deactivated
     */
    public void deactivate(Flight f) throws RemoteException {
        if (f.getDateTime().after(new Date())) {
            Vector bv = bMapper.findByFlight(f);
            Iterator bi = bv.iterator();
            while (bi.hasNext()) {
                Booking b = (Booking) bi.next();
                deactivate(b);
            }
            f.setIsActive(false);
            fMapper.update(f);
        }
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.EE253D10-7DC7-6143-DF02-54445060DC54]
    // </editor-fold>
    /**
     * deactivates a plane object and all plane plus flight objects which are associated to them
     * @param p is the plane object which should be deactivated
     */
    public void deactivate(Plane p) throws RemoteException {
        Vector sv = sMapper.findByPlane(p);
        Iterator si = sv.iterator();
        while (si.hasNext()) {
            Seat s = (Seat) si.next();
            deactivate(s);
        }
        Vector fv = fMapper.findByPlane(p);
        Iterator fi = fv.iterator();
        while (fi.hasNext()) {
            Flight f = (Flight) fi.next();
            deactivate(f);
        }
        p.setIsActive(false);
        pMapper.update(p);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.CD817DAC-D864-E112-B7CA-DF8AF1330663]
    // </editor-fold>
    /**
     * deactivates a seat object by calling the sMapper up
     * @param s is the airline object which should be deactivated
     */
    public void deactivate(Seat s) throws RemoteException {
        s.setIsActive(false);
        sMapper.update(s);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.FBDA796B-1F77-2A55-E29B-DFE676B0770B]
    // </editor-fold>
    /**
     * deactivates a type object and all plane objects which are associated to them
     * @param t is the type object which should be deactivated
     */
    public void deactivate(Type t) throws RemoteException {
        Vector pv = pMapper.findByType(t);
        Iterator pi = pv.iterator();
        while (pi.hasNext()) {
            Plane p = (Plane) pi.next();
            deactivate(p);
        }
        t.setIsActive(false);
        tMapper.update(t);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.AB198B57-2433-5014-E6CB-9CF014106561]
    // </editor-fold>
    /**
     * returns a customer object from the DB by key
     * @param id is the id of the chustomer object which should be retuned
     * @return a customer object
     */
    public Customer getCustomerByKey(int id) throws RemoteException {
        return this.cMapper.findByKey(id);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.4E9A96D0-B35F-9791-2F61-E0E56D8346BA]
    // </editor-fold>
    /**
     * return a customer object from the DB by Lastname
     * @param lastname is the id of the customer object which should be retuned
     * @return a vector containing customer objects
     */
    public Vector<Customer> getCustomerByLastName(String lastname) throws RemoteException {
        return this.cMapper.findByLastname(lastname);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.93AB32C1-7844-2F2A-ABAC-BE1390B6C6E8]
    // </editor-fold>
    /**
     * @return a vector containing all flight objects of a customer
     * @param c is the customer object which flights should be retuned
     */
    public Vector<Flight> getAllFlightsOfCustomer(Customer c) throws RemoteException {
        return this.fMapper.findByCustomer(c);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.8798E549-2CB0-B0EE-A349-E71C0934984C]
    // </editor-fold>
    /**
     * returns all booking objects of a customer
     * @param c is the customer object which bookings should be retuned
     * @return a vector containing booking objects
     */
    public Vector<Booking> getBookingsOfCustomer(Customer c) throws RemoteException {
        return bMapper.findByCustomer(c);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.4F6EFE71-771A-A505-AAB4-E8873FA7FE95]
    // </editor-fold>
    /**
     * returns all booking objects of an specific date
     * @param dateTime is the Date object which bookings should be retuned
     * @return a vector containing booking objects
     */
    public Vector<Booking> findBookingByDateTime(Date dateTime) throws RemoteException {
        return this.bMapper.findByDate(dateTime);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.CDE47A29-A993-D8C5-B0B4-EE5A4CD51198]
    // </editor-fold>
    /**
     * returns all booking objects of a customer by his id
     * @param id is the id of the customer object which bookings should be retuned
     * @return a vector containing booking objects
     */
    public Vector<Booking> findBookingByCustomerId(int id) throws RemoteException {
        return bMapper.findByCustomer(id);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.28ED8C6E-CDF4-F446-7257-808ED798C22A]
    // </editor-fold>
    /**
     * returns a booking object from the DB by key
     * @param id is the id of the booking object which should be retuned
     * @return a booking object
     */
    public Booking findBookingByKey(int id) throws RemoteException {
        return bMapper.findByKey(id);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.49025D80-CA84-2EBF-2BE6-E82218DBDC7C]
    // </editor-fold>
    /**
     * returns a flight object from the DB by key
     * @param id is the id of the flight object which should be retuned
     * @return a flight object
     */
    public Flight findFlightByKey(int id) throws RemoteException {
        return this.fMapper.findByKey(id);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.4D5A42D4-DAE1-4F4C-9D00-27AE39436490]
    // </editor-fold>
    /**
     * @returns all flight objects of a specific date or time
     * @param date is the date object which flights should be retuned
     * @return a vector containing flight objects
     */
    public Vector<Flight> findFlightByDateTime(Date date) throws RemoteException {
        return this.fMapper.findByDate(date);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.FC8E97D4-2740-C062-2CA4-B02EBE5F1759]
    // </editor-fold>
    /**
     * returns all flight objects of a plane
     * @param p is the plane object which flights should be retuned
     * @return a vector containing flight objects
     */
    public Vector<Flight> findFlightByPlane(Plane p) throws RemoteException {
        return this.fMapper.findByPlane(p);
    }

    /**
     * returns all flight objects of a plane by id
     * @param planeId is the id of the plane object which flights should be returned
     * @return a vector containing flight objects
     */
    public Vector<Flight> findFlightByPlane(int planeId) throws RemoteException {
        return this.fMapper.findByPlane(planeId);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.0CBE373E-91B7-40AC-4F79-2C2CFD2E5889]
    // </editor-fold>
    /**
     * returns all flight objects of a start airport
     * @param a is the  airport object which flights should be returned
     * @return a vector containing flight objects
     */
    public Vector<Flight> findFlightByStartAirport(Airport a) throws RemoteException {
        return this.fMapper.findByStartAirport(a);
    }

    /**
     * returns all flight objects of a start airport by id
     * @param startAirportId is the the id of the startAirport object which flights should be returned
     * @return a vector containing flight objects
     */
    public Vector<Flight> findFlightByStartAirport(int startAirportId) throws RemoteException {
        return this.fMapper.findByStartAirport(startAirportId);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.AB7C349F-C663-B93D-6608-31A4910796A1]
    // </editor-fold>
    /**
     * returns all flight objects of a destination Airport
     * @param a is the Airport object which flights should be returned
     * @return a vector containing flight objects
     */
    public Vector<Flight> findFlightByDestAirport(Airport a) throws RemoteException {
        return this.fMapper.findByDestAirport(a);
    }

    /**
     * returns all flight objects of a destination Airport
     * @param destAirportId is the Airport Id of the Airport object which flights should be returned
     * @return a vector containing flight objects
     */
    public Vector<Flight> findFlightByDestAirport(int destAirportId) throws RemoteException {
        return this.fMapper.findByDestAirport(destAirportId);
    }

    /**
     * returns all flight objects of a Customer
     * @param c is the Customer object which flights should be returned
     * @return a vector containing flight objects
     */
    public Vector<Flight> findFlightByCustomer(Customer c) throws RemoteException {
        return this.fMapper.findByCustomer(c);
    }

    /**
     * returns all flight objects of a Customer
     * @param customerId is the Customer Id of the Customer object which flights should be returned
     * @return a vector containing flight objects
     */
    public Vector<Flight> findFlightByCustomer(int customerId) throws RemoteException {
        return this.fMapper.findByCustomer(customerId);
    }

    /**
     * returns all flight objects of a Customer with an Airline
     * @param customerId is the Customer Id of the Customer object which flights should be returned
     * @param airlineId is the Airline Id of the Airline object which flights should be returned
     * @return a vector containing flight objects
     */
    public Vector<Flight> findFlightByCustomerAndAirline(int customerId, int airlineId) throws RemoteException {
        return this.fMapper.findByCustomerAndAirline(customerId, airlineId);
    }

    /**
     * returns all flight objects of a Customer with an Airline
     * @param c is the Customer Id of the Customer object which flights should be retuned
     * @param a is the Airline Id of the Airline object which flights should be retuned
     * @return a vector containing flight objects
     */
    public Vector<Flight> findFlightByCustomerAndAirline(Customer c, Airline a) throws RemoteException {
        return this.fMapper.findByCustomerAndAirline(c, a);
    }

    /**
     * returns all flight objects of a Customer beteen two dates
     * @param customerId is the Customer Id of the Customer object which flights should be returned
     * @param fromDate the first date of the dates between the flights should
     * be searched
     * @param toDate the second date of the dates between the flights should
     * be searched
     * @return a vector containing flight objects
     */
    public Vector<Flight> findFlightByCustomerAndPeriod(Customer c, Date fromDate, Date toDate) throws RemoteException {
        return this.fMapper.findByCustomerAndPeriod(c, fromDate, toDate);
    }
    
    /**
     * returns all flight objects of a Customer between two dates
     * @param customerId is the Customer Id of the Customer object which flights should be returned
     * @param fromDate the first date of the dates between the flights should
     * be searched
     * @param toDate the second date of the dates between the flights should
     * be searched
     * @return a vector containing flight objects
     */
    public Vector<Flight> findFlightByCustomerAndPeriod(int customerId, Date fromDate, Date toDate) throws RemoteException {
        return this.fMapper.findByCustomerAndPeriod(customerId, fromDate, toDate);
    }

    /**
     * returns all flight objects of a Customer with an Airline between two dates
     * @param customerId is the Customer Id of the Customer object which flights should be returned
     * @param airlineId is the Airline Id of the Airline object which flights should be returned
     * @param fromDate the first date of the dates between the flights should
     * be searched
     * @param toDate the second date of the dates between the flights should
     * be searched
     * @return a vector containing flight objects
     */
    public Vector<Flight> findFlightByCustomerAndAirlineAndPeriod(int customerId, int airlineId, Date fromDate, Date toDate) throws RemoteException {
        return this.fMapper.findByCustomerAndAirlineAndPeriod(customerId, airlineId, fromDate, toDate);
    }

    /**
     * returns all flight objects of a Customer with an Airline between two dates
     * @param c is the Customer Id of the Customer object which flights should be retuned
     * @param a is the Airline Id of the Airline object which flights should be retuned
     * @param fromDate the first date of the dates between the flights should
     * be searched
     * @param toDate the second date of the dates between the flights should
     * be searched
     * @return a vector containing flight objects
     */
    public Vector<Flight> findFlightByCustomerAndAirlineAndPeriod(Customer c, Airline a, Date fromDate, Date toDate) throws RemoteException {
        return this.fMapper.findByCustomerAndAirlineAndPeriod(c, a, fromDate, toDate);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.E4D0F236-BB43-DCDA-964C-2CD0FF374B32]
    // </editor-fold>
    /**
     * returns a plane object from the DB by key
     * @param planeId is the id of the plane object which should be returned
     * @return a vector containing flight objects
     */
    public Plane findPlaneByKey(int planeId) throws RemoteException {
        return this.pMapper.findByKey(planeId);
    }

    /**
     * returns a plane object from the DB by type
     * @param t is the type of the plane object which should be returned
     * @return a vector containing plane objects
     */
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.05DB07E7-730B-8614-DEC2-D04A6D73CCCC]
    // </editor-fold> 
    public Vector<Plane> findPlaneByType(Type t) throws RemoteException {
        return this.pMapper.findByType(t);
    }

    /**
     * returns a plane object from the DB by airline
     * @param a is the airline of the plane object which should be returned
     * @return a vector containing plane objects
     */
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.AD8BB97E-0D48-91E0-4B7F-E4A8DC1B266D]
    // </editor-fold> 
    public Vector<Plane> findPlaneByAirline(Airline a) throws RemoteException {
        return this.pMapper.findByAirline(a);
    }

    /**
     * returns a seat object from the DB by id
     * @param seatId is the id of the seat object which should be returned
     * @return a seat object
     */
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.6562926F-6C0A-3574-09BC-C7AA92B4AA6E]
    // </editor-fold> 
    public Seat findSeatByKey(int seatId) throws RemoteException {
        return this.sMapper.findByKey(seatId);
    }

    /**
     * returns a seat object from the DB by plane
     * @param p is the plane in which the seat is existing
     * @return a vector containing seat objects
     */
    public Vector<Seat> findSeatByPlane(Plane p) throws RemoteException {
        return this.sMapper.findByPlane(p);
    }

    /**
     * returns a seat object from the DB by plane
     * @param planeId is the id of the plane object in which the seat is existing
     * @return a vector containing seat objects
     */
    public Vector<Seat> findSeatByPlane(int planeId) throws RemoteException {
        return this.sMapper.findByPlane(planeId);
    }

    /**
     * returns a seat object from the DB which is at the passed row, seat and plane
     * @param row is the row in which the seat is 
     * @param seat is the place of the seat 
     * @param p is the plane in which the seat is existing
     * @return a seat object
     */
    public Seat findSeatByRowSeatPlane(int row, char seat, Plane p) throws RemoteException {
        return this.sMapper.findByRowSeatPlane(row, seat, p);
    }

    /**
     * returns a seat object from the DB which is at the passed row, seat and plane Id
     * @param row is the row in which the seat is 
     * @param seat is the place of the seat 
     * @param planeId is the plane in which the seat is existing
     * @return a seat object
     */
    public Seat findSeatByRowSeatPlane(int row, char seat, int planeId) throws RemoteException {
        return this.sMapper.findByRowSeatPlane(row, seat, planeId);
    }

    /**
     * returns a seat object from the DB which is booked for the passed flight
     * @param f the passed flight
     * @return a vector containing seat objects
     */
    public Vector<Seat> findBookedSeatByFlight(Flight f) throws RemoteException {
        return this.sMapper.findBookedByFlight(f);
    }

    /**
     * returns a seat object from the DB which is booked for the passed flight
     * @param flightId the ID of the passed flight
     * @return a vector containing seat objects
     */
    public Vector<Seat> findBookedSeatByFlight(int flightId) throws RemoteException {
        return this.sMapper.findBookedByFlight(flightId);
    }

    /**
     * returns a booking object from the DB by a passed flight and seat
     * @param flightId the passed id of the flight
     * @param seatId the passed id of the seat
     * @return a booking object
     */
    public Booking findBookingByFlightAndSeat(int flightId, int seatId) throws RemoteException {
        return this.bMapper.findBookingByFlightAndSeat(flightId, seatId);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.4F3DE9DA-C502-17EF-DEF6-6DE304B132B9]
    // </editor-fold>
    /**
     * returns a type object from the DB by key
     * @param typeId is the id of the type object which should be retuned
     * @return a type object
     */
    public Type findTypeByKey(int typeId) throws RemoteException {
        return this.tMapper.findByKey(typeId);
    }

    /**
     * returns type objects from the DB by name
     * @param name is the name of the type object which should be returned
     * @return a vector of type objects 
     */
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.DE34C2AD-8413-C788-6A49-22E5507A11E8]
    // </editor-fold> 
    public Vector<Type> findTypeByName(String name) throws RemoteException {
        return this.tMapper.findByName(name);
    }

    /**
     * returns type objects from the DB by seats total
     * @param seatsTotal the total seats of type object which should be returned
     * @return a vector of type objects 
     */
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.48A12AE2-2AD3-1E9A-19AC-C4B3490DF49B]
    // </editor-fold> 
    public Vector<Type> findTypeBySeatsTotal(int seatsTotal) throws RemoteException {
        return null;
    }

    /**
     * returns type objects from the DB by min seats total
     * @param seatsTotal the minimal seats of a type object which should be returned
     * @return a vector of type objects
     * @throws RemoteException
     */
    public Vector<Type> findTypeByMinSeatsTotal(int seatsTotal) throws RemoteException {
        return this.tMapper.findByMinSeatsTotal(seatsTotal);
    }

    /**
     * returns airline objects from the DB by name
     * @param name is the name of the airline object which should be returned
     * @return a vector of airline objects 
     */
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.51B58DD4-9F2E-F319-0E71-E5361B58C77B]
    // </editor-fold> 
    public Vector<Airline> findAirlineByName(String name) throws RemoteException {
        return this.airlMapper.findByName(name);
    }

    /**
     * returns airline objects from the DB by initials
     * @param initials is the initial of the airline object which should be returned
     * @return a vector of airline objects 
     */
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.7835FC50-77DB-A866-B11B-E62840C83404]
    // </editor-fold> 
    public Vector<Airline> findAirlineByInitials(String initials) throws RemoteException {
        return this.airlMapper.findByInitials(initials);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.C6000336-4442-2F6D-C61A-0104237107D5]
    // </editor-fold>
    /**
     * returns a airline object from the DB by key
     * @param airlineId is the id of the airline object which should be retuned
     * @return a airline object
     */
    public Airline findAirlineByKey(int airlineId) throws RemoteException {
        return this.airlMapper.findByKey(airlineId);
    }

    /**
     * returns a airport object from the DB by key
     * @param airportId is the id of the airport object which should be retuned
     * @return The Airport with index <code>airportId</code>
     */
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.C7D22DCC-2EEB-A9F1-6A20-C10F52502D59]
    // </editor-fold>
    public Airport findAirportByKey(int airportId) throws RemoteException {
        return this.airpMapper.findByKey(airportId);
    }

    /**
     * returns airport objects from the DB by name
     * @param name is the name of the airport object which should be returned
     * @return a vector of airport objects 
     */
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.93950DAA-D361-CF20-0F37-287DCB91374A]
    // </editor-fold> 
    public Vector<Airport> findAirportByName(String name) throws RemoteException {
        return this.airpMapper.findByName(name);
    }

    /**
     * returns airport objects from the DB by initials
     * @param initials is the initial of the airport object which should be returned
     * @return a vector of airport objects 
     */
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.83C918F6-917C-0CD9-B670-C8B779181FAE]
    // </editor-fold> 
    public Vector<Airport> findAirportByInitials(String initials) throws RemoteException {
        return this.airpMapper.findByInitials(initials);
    }

    /**
     * returns airport objects from the DB by city
     * @param city is the city of the airport object which should be returned
     * @return a vector of airport objects 
     */
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.043F7E46-6335-DD85-70F1-BD6DDFCB1555]
    // </editor-fold> 
    public Vector<Airport> findAirportByCity(String city) throws RemoteException {
        return this.airpMapper.findByCity(city);
    }

    /**
     * returns plane objects from the DB by name
     * @param name is the name of the plane object which should be returned
     * @return a vector of plane objects 
     */
    public Vector<Plane> findPlaneByName(String name) throws RemoteException {
        return this.pMapper.findByName(name);
    }

    /**
     * creates a new type object
     * @param name is the name of the type object which should be created
     * @param rows is the number of rows of the created type
     * @param columns is the number of columns of the created type object which should be created
     * @return a type object
     * @throws RemoteException
     */
    public Type createType(String name, String rows, String columns) throws RemoteException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * returns the report generator object from above
     * @return a ReportGenerator object
     */
    public ReportGenerator getReportGenerator() throws RemoteException {
        reportGenerator = new ReportGeneratorImpl(this);
        return this.reportGenerator;
    }
}